#ifndef _STRAWGUI_COMPONENT_H_
#define _STRAWGUI_COMPONENT_H_

#include "sNamedObject.h"
#include "sLinkTo.h"
#include "sTRFrame.h"
#include "sComponentRect.h"
#include "DataBase.h"

namespace sgui
{
namespace inst
{
	class sComponentInstance;
};
namespace res
{

struct sRequiredComponentRect
{
    sComponentRect*                     m_rect;
    sComponentRect::EComponentRectType  m_type;

    sRequiredComponentRect(sComponentRect::EComponentRectType type) : m_type(type), m_rect(NULL) {}
};

class sComponent : public sNamedObject
{
private:
	std::deque<sComponentRect*>             m_componentRects;
    std::deque<sRequiredComponentRect>      m_requiredRects;
	math::sRectsf                           m_rect;
protected:
    void registerRequiredComponentRect(sComponentRect::EComponentRectType type);
public:
    math::sRectsf& getRect() { return m_rect; }
    const math::sRectsf& getRect() const { return m_rect; }

    std::deque<sComponentRect*>& getComponentRects() { return m_componentRects; }
    const std::deque<sComponentRect*>& getComponentRects() const { return m_componentRects; }

    std::deque<sRequiredComponentRect>& getRequiredComponentRects() { return m_requiredRects; }
    const std::deque<sRequiredComponentRect>& getRequiredComponentRects() const { return m_requiredRects; }

    void load(db::Record &file);
    void save(db::Record &file);
	void clear();
    void init();

    void setRequiredRect(u32 idx, sComponentRect* rect);
    bool isValid() const;

	virtual	inst::sComponentInstance* getInstance(sGUI& gui, const res::sComponentObject& object, inst::sComponentInstance* parent) = 0;
    virtual const std::wstring getClass() const = 0;
    virtual void fillRequredRects() = 0;

    sComponent(sGUI& gui, const std::wstring& name);
    virtual ~sComponent();
};

};
};

#endif